﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BusinessLayer.DatabaseEntities;
using BusinessLayer.VDataEntities;
using CustomerServiceCenter.Models;
using CustomerServiceCenter.Helper;

namespace CustomerServiceCenter.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Login()
        {
            return View();
        }
        [LoginAuthorize]
        public ActionResult ResetPassword()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                using (CustomerServiceCenterEntities entities = new CustomerServiceCenterEntities())
                {

                    var loginInfo = (from info in entities.Operator
                                     where info.UserName.Equals(model.UserName) && info.Password.Equals(model.Password) && info.IsActive == true
                                     select info).FirstOrDefault();
                    if (loginInfo != null)
                    {
                        Session["adminLoginInfo"] = loginInfo;
                        return RedirectToAction("TicketsRequestInfo", "Tickets");
                    }
                }
            }
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
           return View(model);
        }


    }
}
